package com.ruoyi.manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.cg.dto.GroupStatusDto;
import com.ruoyi.common.core.cg.pojo.Group;
import com.ruoyi.common.core.cg.pojo.Store;
import com.ruoyi.common.core.cg.result.Result;
import com.ruoyi.manage.mapper.GroupMapper;
import com.ruoyi.manage.mapper.OrderMapper;
import com.ruoyi.manage.mapper.StoreMapper;
import com.ruoyi.manage.service.GroupManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 马景昌
 * @create 2025/03/10
 * @description
 */
@Service
public class GroupManageServiceImpl implements GroupManageService {
    @Autowired
    private GroupMapper groupMapper;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private OrderMapper orderMapper;


    @Override
    public Result pageshow(Integer pageNum, Integer pageSize, Group group) {
        if(pageNum==null && pageSize==null){
            pageNum=1;
            pageSize=5;

        }
        PageHelper.startPage(pageNum,pageSize);
        List<Group> pageshow = groupMapper.pageshowa(group);
        for (Group group1 : pageshow) {
//            商铺名称
            Store store = storeMapper.selectBygid(group1.getId());
            if(store!=null){
                group1.setStoreName(store.getName());
            }else {
                group1.setStoreName("目前没有商铺");
            }

//一个团可以有多个订单
            Integer integer = orderMapper.selectordercount0(group1.getId());
            group1.setItemStatus0(integer);
            Integer integer1 = orderMapper.selectordercount1(group1.getId());
            group1.setItemStatus1(integer1);
        }
        PageInfo<Group> pageInfo = new PageInfo<>(pageshow);
        System.out.println(pageInfo.getTotal());
        return new Result(true,"查询成功",pageInfo);
    }

    @Override
    public Result updatestatus(Integer id,Integer groupStatus) {
        boolean updatestatus = groupMapper.updatestatus(id,groupStatus);
        if(!updatestatus){
            return new Result(false,"修改失败");
        }
        return new Result(true,"修改成功");
    }

}

